﻿/*
 JuCheap Ids(身份认证系统数据库结构&初始数据)
*/

use [JuCheapCore4-Ids]
go

-- ----------------------------
-- Table structure for ApiClaims
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ApiClaims]') AND type IN ('U'))
	DROP TABLE [dbo].[ApiClaims]
GO

CREATE TABLE [dbo].[ApiClaims] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ApiResourceId] int  NOT NULL,
  [Type] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ApiClaims] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ApiResources
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ApiResources]') AND type IN ('U'))
	DROP TABLE [dbo].[ApiResources]
GO

CREATE TABLE [dbo].[ApiResources] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Description] nvarchar(1000) COLLATE Chinese_PRC_CI_AS  NULL,
  [DisplayName] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [Enabled] bit  NOT NULL,
  [Name] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ApiResources] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [ApiResources]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[ApiResources] ON
GO

INSERT INTO [dbo].[ApiResources] ([Id], [Description], [DisplayName], [Enabled], [Name]) VALUES (N'1', N'JuCheapApi', N'JuCheapApi', N'1', N'JuCheapApi')
GO

SET IDENTITY_INSERT [dbo].[ApiResources] OFF
GO


-- ----------------------------
-- Table structure for ApiScopeClaims
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ApiScopeClaims]') AND type IN ('U'))
	DROP TABLE [dbo].[ApiScopeClaims]
GO

CREATE TABLE [dbo].[ApiScopeClaims] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ApiScopeId] int  NOT NULL,
  [Type] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ApiScopeClaims] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ApiScopes
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ApiScopes]') AND type IN ('U'))
	DROP TABLE [dbo].[ApiScopes]
GO

CREATE TABLE [dbo].[ApiScopes] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ApiResourceId] int  NOT NULL,
  [Description] nvarchar(1000) COLLATE Chinese_PRC_CI_AS  NULL,
  [DisplayName] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [Emphasize] bit  NOT NULL,
  [Name] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Required] bit  NOT NULL,
  [ShowInDiscoveryDocument] bit  NOT NULL
)
GO

ALTER TABLE [dbo].[ApiScopes] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [ApiScopes]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[ApiScopes] ON
GO

INSERT INTO [dbo].[ApiScopes] ([Id], [ApiResourceId], [Description], [DisplayName], [Emphasize], [Name], [Required], [ShowInDiscoveryDocument]) VALUES (N'1', N'1', N'JuCheapApi', N'JuCheapApi', N'0', N'JuCheapApi', N'1', N'1')
GO

SET IDENTITY_INSERT [dbo].[ApiScopes] OFF
GO


-- ----------------------------
-- Table structure for ApiSecrets
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ApiSecrets]') AND type IN ('U'))
	DROP TABLE [dbo].[ApiSecrets]
GO

CREATE TABLE [dbo].[ApiSecrets] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ApiResourceId] int  NOT NULL,
  [Description] nvarchar(1000) COLLATE Chinese_PRC_CI_AS  NULL,
  [Expiration] datetime2(7)  NULL,
  [Type] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NULL,
  [Value] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL
)
GO

ALTER TABLE [dbo].[ApiSecrets] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientClaims
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientClaims]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientClaims]
GO

CREATE TABLE [dbo].[ClientClaims] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Type] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Value] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientClaims] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientCorsOrigins
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientCorsOrigins]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientCorsOrigins]
GO

CREATE TABLE [dbo].[ClientCorsOrigins] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Origin] nvarchar(150) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientCorsOrigins] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientGrantTypes
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientGrantTypes]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientGrantTypes]
GO

CREATE TABLE [dbo].[ClientGrantTypes] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [GrantType] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientGrantTypes] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [ClientGrantTypes]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[ClientGrantTypes] ON
GO

INSERT INTO [dbo].[ClientGrantTypes] ([Id], [ClientId], [GrantType]) VALUES (N'1', N'2', N'password')
GO

INSERT INTO [dbo].[ClientGrantTypes] ([Id], [ClientId], [GrantType]) VALUES (N'2', N'2', N'client_credentials')
GO

SET IDENTITY_INSERT [dbo].[ClientGrantTypes] OFF
GO


-- ----------------------------
-- Table structure for ClientIdPRestrictions
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientIdPRestrictions]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientIdPRestrictions]
GO

CREATE TABLE [dbo].[ClientIdPRestrictions] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Provider] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientIdPRestrictions] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientPostLogoutRedirectUris
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientPostLogoutRedirectUris]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientPostLogoutRedirectUris]
GO

CREATE TABLE [dbo].[ClientPostLogoutRedirectUris] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [PostLogoutRedirectUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientPostLogoutRedirectUris] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientProperties
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientProperties]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientProperties]
GO

CREATE TABLE [dbo].[ClientProperties] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Key] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Value] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientProperties] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ClientRedirectUris
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientRedirectUris]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientRedirectUris]
GO

CREATE TABLE [dbo].[ClientRedirectUris] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [RedirectUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientRedirectUris] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Clients
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Clients]') AND type IN ('U'))
	DROP TABLE [dbo].[Clients]
GO

CREATE TABLE [dbo].[Clients] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [AbsoluteRefreshTokenLifetime] int  NOT NULL,
  [AccessTokenLifetime] int  NOT NULL,
  [AccessTokenType] int  NOT NULL,
  [AllowAccessTokensViaBrowser] bit  NOT NULL,
  [AllowOfflineAccess] bit  NOT NULL,
  [AllowPlainTextPkce] bit  NOT NULL,
  [AllowRememberConsent] bit  NOT NULL,
  [AlwaysIncludeUserClaimsInIdToken] bit  NOT NULL,
  [AlwaysSendClientClaims] bit  NOT NULL,
  [AuthorizationCodeLifetime] int  NOT NULL,
  [BackChannelLogoutSessionRequired] bit  NOT NULL,
  [BackChannelLogoutUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL,
  [ClientClaimsPrefix] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [ClientId] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [ClientName] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [ClientUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL,
  [ConsentLifetime] int  NULL,
  [Description] nvarchar(1000) COLLATE Chinese_PRC_CI_AS  NULL,
  [EnableLocalLogin] bit  NOT NULL,
  [Enabled] bit  NOT NULL,
  [FrontChannelLogoutSessionRequired] bit  NOT NULL,
  [FrontChannelLogoutUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL,
  [IdentityTokenLifetime] int  NOT NULL,
  [IncludeJwtId] bit  NOT NULL,
  [LogoUri] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL,
  [PairWiseSubjectSalt] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [ProtocolType] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [RefreshTokenExpiration] int  NOT NULL,
  [RefreshTokenUsage] int  NOT NULL,
  [RequireClientSecret] bit  NOT NULL,
  [RequireConsent] bit  NOT NULL,
  [RequirePkce] bit  NOT NULL,
  [SlidingRefreshTokenLifetime] int  NOT NULL,
  [UpdateAccessTokenClaimsOnRefresh] bit  NOT NULL
)
GO

ALTER TABLE [dbo].[Clients] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [Clients]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[Clients] ON
GO

INSERT INTO [dbo].[Clients] ([Id], [AbsoluteRefreshTokenLifetime], [AccessTokenLifetime], [AccessTokenType], [AllowAccessTokensViaBrowser], [AllowOfflineAccess], [AllowPlainTextPkce], [AllowRememberConsent], [AlwaysIncludeUserClaimsInIdToken], [AlwaysSendClientClaims], [AuthorizationCodeLifetime], [BackChannelLogoutSessionRequired], [BackChannelLogoutUri], [ClientClaimsPrefix], [ClientId], [ClientName], [ClientUri], [ConsentLifetime], [Description], [EnableLocalLogin], [Enabled], [FrontChannelLogoutSessionRequired], [FrontChannelLogoutUri], [IdentityTokenLifetime], [IncludeJwtId], [LogoUri], [PairWiseSubjectSalt], [ProtocolType], [RefreshTokenExpiration], [RefreshTokenUsage], [RequireClientSecret], [RequireConsent], [RequirePkce], [SlidingRefreshTokenLifetime], [UpdateAccessTokenClaimsOnRefresh]) VALUES (N'2', N'2592000', N'3600', N'0', N'0', N'0', N'0', N'1', N'0', N'0', N'300', N'1', NULL, N'client_', N'JuCheapApi', N'JuCheapWebApi', NULL, NULL, NULL, N'1', N'1', N'0', NULL, N'300', N'0', NULL, NULL, N'oidc', N'1', N'1', N'1', N'1', N'0', N'1296000', N'0')
GO

SET IDENTITY_INSERT [dbo].[Clients] OFF
GO


-- ----------------------------
-- Table structure for ClientScopes
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientScopes]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientScopes]
GO

CREATE TABLE [dbo].[ClientScopes] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Scope] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientScopes] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [ClientScopes]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[ClientScopes] ON
GO

INSERT INTO [dbo].[ClientScopes] ([Id], [ClientId], [Scope]) VALUES (N'1', N'2', N'JuCheapApi')
GO

SET IDENTITY_INSERT [dbo].[ClientScopes] OFF
GO


-- ----------------------------
-- Table structure for ClientSecrets
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientSecrets]') AND type IN ('U'))
	DROP TABLE [dbo].[ClientSecrets]
GO

CREATE TABLE [dbo].[ClientSecrets] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [ClientId] int  NOT NULL,
  [Description] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NULL,
  [Expiration] datetime2(7)  NULL,
  [Type] nvarchar(250) COLLATE Chinese_PRC_CI_AS  NULL,
  [Value] nvarchar(2000) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[ClientSecrets] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Records of [ClientSecrets]
-- ----------------------------
SET IDENTITY_INSERT [dbo].[ClientSecrets] ON
GO

INSERT INTO [dbo].[ClientSecrets] ([Id], [ClientId], [Description], [Expiration], [Type], [Value]) VALUES (N'1', N'2', NULL, NULL, N'SharedSecret', N'CAKfYX//jJekmfx/6jVy4bPnIGactt7AdAoP9fUgMQA=')
GO

SET IDENTITY_INSERT [dbo].[ClientSecrets] OFF
GO


-- ----------------------------
-- Table structure for IdentityClaims
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[IdentityClaims]') AND type IN ('U'))
	DROP TABLE [dbo].[IdentityClaims]
GO

CREATE TABLE [dbo].[IdentityClaims] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [IdentityResourceId] int  NOT NULL,
  [Type] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[IdentityClaims] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for IdentityResources
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[IdentityResources]') AND type IN ('U'))
	DROP TABLE [dbo].[IdentityResources]
GO

CREATE TABLE [dbo].[IdentityResources] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Description] nvarchar(1000) COLLATE Chinese_PRC_CI_AS  NULL,
  [DisplayName] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [Emphasize] bit  NOT NULL,
  [Enabled] bit  NOT NULL,
  [Name] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Required] bit  NOT NULL,
  [ShowInDiscoveryDocument] bit  NOT NULL
)
GO

ALTER TABLE [dbo].[IdentityResources] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for PersistedGrants
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[PersistedGrants]') AND type IN ('U'))
	DROP TABLE [dbo].[PersistedGrants]
GO

CREATE TABLE [dbo].[PersistedGrants] (
  [Key] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [ClientId] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [CreationTime] datetime2(7)  NOT NULL,
  [Data] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Expiration] datetime2(7)  NULL,
  [SubjectId] nvarchar(200) COLLATE Chinese_PRC_CI_AS  NULL,
  [Type] nvarchar(50) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[PersistedGrants] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Primary Key structure for table ApiClaims
-- ----------------------------
ALTER TABLE [dbo].[ApiClaims] ADD CONSTRAINT [PK_ApiClaims] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ApiResources
-- ----------------------------
ALTER TABLE [dbo].[ApiResources] ADD CONSTRAINT [PK_ApiResources] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ApiScopeClaims
-- ----------------------------
ALTER TABLE [dbo].[ApiScopeClaims] ADD CONSTRAINT [PK_ApiScopeClaims] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ApiScopes
-- ----------------------------
ALTER TABLE [dbo].[ApiScopes] ADD CONSTRAINT [PK_ApiScopes] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ApiSecrets
-- ----------------------------
ALTER TABLE [dbo].[ApiSecrets] ADD CONSTRAINT [PK_ApiSecrets] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientClaims
-- ----------------------------
ALTER TABLE [dbo].[ClientClaims] ADD CONSTRAINT [PK_ClientClaims] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientCorsOrigins
-- ----------------------------
ALTER TABLE [dbo].[ClientCorsOrigins] ADD CONSTRAINT [PK_ClientCorsOrigins] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientGrantTypes
-- ----------------------------
ALTER TABLE [dbo].[ClientGrantTypes] ADD CONSTRAINT [PK_ClientGrantTypes] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientIdPRestrictions
-- ----------------------------
ALTER TABLE [dbo].[ClientIdPRestrictions] ADD CONSTRAINT [PK_ClientIdPRestrictions] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientPostLogoutRedirectUris
-- ----------------------------
ALTER TABLE [dbo].[ClientPostLogoutRedirectUris] ADD CONSTRAINT [PK_ClientPostLogoutRedirectUris] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientProperties
-- ----------------------------
ALTER TABLE [dbo].[ClientProperties] ADD CONSTRAINT [PK_ClientProperties] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientRedirectUris
-- ----------------------------
ALTER TABLE [dbo].[ClientRedirectUris] ADD CONSTRAINT [PK_ClientRedirectUris] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table Clients
-- ----------------------------
ALTER TABLE [dbo].[Clients] ADD CONSTRAINT [PK_Clients] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientScopes
-- ----------------------------
ALTER TABLE [dbo].[ClientScopes] ADD CONSTRAINT [PK_ClientScopes] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ClientSecrets
-- ----------------------------
ALTER TABLE [dbo].[ClientSecrets] ADD CONSTRAINT [PK_ClientSecrets] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table IdentityClaims
-- ----------------------------
ALTER TABLE [dbo].[IdentityClaims] ADD CONSTRAINT [PK_IdentityClaims] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table IdentityResources
-- ----------------------------
ALTER TABLE [dbo].[IdentityResources] ADD CONSTRAINT [PK_IdentityResources] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Indexes structure for table PersistedGrants
-- ----------------------------
CREATE NONCLUSTERED INDEX [IX_PersistedGrants_SubjectId_ClientId_Type]
ON [dbo].[PersistedGrants] (
  [SubjectId] ASC,
  [ClientId] ASC,
  [Type] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table PersistedGrants
-- ----------------------------
ALTER TABLE [dbo].[PersistedGrants] ADD CONSTRAINT [PK_PersistedGrants] PRIMARY KEY CLUSTERED ([Key])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Foreign Keys structure for table ApiClaims
-- ----------------------------
ALTER TABLE [dbo].[ApiClaims] ADD CONSTRAINT [FK_ApiClaims_ApiResources_ApiResourceId] FOREIGN KEY ([ApiResourceId]) REFERENCES [ApiResources] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ApiScopeClaims
-- ----------------------------
ALTER TABLE [dbo].[ApiScopeClaims] ADD CONSTRAINT [FK_ApiScopeClaims_ApiScopes_ApiScopeId] FOREIGN KEY ([ApiScopeId]) REFERENCES [ApiScopes] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ApiScopes
-- ----------------------------
ALTER TABLE [dbo].[ApiScopes] ADD CONSTRAINT [FK_ApiScopes_ApiResources_ApiResourceId] FOREIGN KEY ([ApiResourceId]) REFERENCES [ApiResources] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ApiSecrets
-- ----------------------------
ALTER TABLE [dbo].[ApiSecrets] ADD CONSTRAINT [FK_ApiSecrets_ApiResources_ApiResourceId] FOREIGN KEY ([ApiResourceId]) REFERENCES [ApiResources] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientClaims
-- ----------------------------
ALTER TABLE [dbo].[ClientClaims] ADD CONSTRAINT [FK_ClientClaims_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientCorsOrigins
-- ----------------------------
ALTER TABLE [dbo].[ClientCorsOrigins] ADD CONSTRAINT [FK_ClientCorsOrigins_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientGrantTypes
-- ----------------------------
ALTER TABLE [dbo].[ClientGrantTypes] ADD CONSTRAINT [FK_ClientGrantTypes_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientIdPRestrictions
-- ----------------------------
ALTER TABLE [dbo].[ClientIdPRestrictions] ADD CONSTRAINT [FK_ClientIdPRestrictions_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientPostLogoutRedirectUris
-- ----------------------------
ALTER TABLE [dbo].[ClientPostLogoutRedirectUris] ADD CONSTRAINT [FK_ClientPostLogoutRedirectUris_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientProperties
-- ----------------------------
ALTER TABLE [dbo].[ClientProperties] ADD CONSTRAINT [FK_ClientProperties_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientRedirectUris
-- ----------------------------
ALTER TABLE [dbo].[ClientRedirectUris] ADD CONSTRAINT [FK_ClientRedirectUris_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientScopes
-- ----------------------------
ALTER TABLE [dbo].[ClientScopes] ADD CONSTRAINT [FK_ClientScopes_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table ClientSecrets
-- ----------------------------
ALTER TABLE [dbo].[ClientSecrets] ADD CONSTRAINT [FK_ClientSecrets_Clients_ClientId] FOREIGN KEY ([ClientId]) REFERENCES [Clients] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO


-- ----------------------------
-- Foreign Keys structure for table IdentityClaims
-- ----------------------------
ALTER TABLE [dbo].[IdentityClaims] ADD CONSTRAINT [FK_IdentityClaims_IdentityResources_IdentityResourceId] FOREIGN KEY ([IdentityResourceId]) REFERENCES [IdentityResources] ([Id]) ON DELETE CASCADE ON UPDATE NO ACTION
GO



